<template>
	<div id="app">
		<div id="my_note">
			<div class="nav">
				<ul class="am-avg-sm-2">
					<li><a class="cur"  @click="uni.redirectTo({
						url:'my_note'
					})">已发表</a></li>
					<li><a  @click="uni.redirectTo({
						url:'box'
					})">草稿箱</a></li>
				</ul>
			</div>
			<div class="cont">
				<div id="app">
					<ul v-for="(b,bi) in articles" v-bind:key="bi">
						<li >
							<div class="box_cont" @click="itemClicked(b)">
								<a title="">
									<div class="pic">
										<img :src="'https://yo.docshare.org.cn'+b.background">
									</div>
									<div class="project_cont">
										<p>{{b.articletitle}}</p>
									</div>
									<div class="clear"></div>
								</a>
							</div>
							<span class="date">{{b.articletime}}</span>
							<!-- <div class="button">
								<input type="submit" class="gray_hollow" @click="delete1(b)" value="删除" />
							</div> -->
							<button class="button"  @click="delete1(b)">删除</button>
						</li>
					</ul>
					<div id="none">
						没有更多了
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import config from '@/config'
	export default {
				data() {
					return {
						uni,
						aid: '',
						articles: {},
						id: ''
					}
				},
				methods: {
					itemClicked: function(item) {
						debugger
						uni.navigateTo({
							url:`add_detail?id=${item.id}`
						})
					},
					delete1: function(item) {
						this.id = item.id;
						uni.request({
							url: `${config.baseUrl}/article/delete1?token=` + uni.getStorageSync('token'),
							data:{
								'id': this.id,
							},
							method: 'POST',
							success(r) {
								if (r.data.succ) {
									uni.navigateTo({
										url:'my_note'
									})
								} 
							},
							complete(res){
								if(res.data && res.data.msg){
									uni.showToast({
										icon:'none',
										title:res.data.msg
									})
								}
							},
						});
					},
				},
				onLoad() {
					var that = this;
					uni.request({
						url: `${config.baseUrl}/article/posted?token=${uni.getStorageSync('token')}`,
						method: "GET",
						success(r) {
							if (r.data.succ) {
								that.articles = r.data.data;
							} 
						},
							complete(res){
								if(res.data && res.data.msg){
									uni.showToast({
										icon:'none',
										title:res.data.msg
									})
								}
							},
					})
				}
			}
</script>

<style>
</style>
